/**
 * Copyright (c) 2017,http://www.365wuliu.com/  All Rights Reserved.
 */
package com.cargo.base.utils;

import java.util.Random;

/** 
 * CaptchaUtil:验证类统一
 * @Project Name:topsales_services 
 * @File Name:CaptchaUtil.java 
 * @Package Name:com.cargo.base.utils
 * @Creator:lizhongchang
 * @Date:2017年9月14日下午1:20:51 
 */
public class CaptchaUtil {
	
	//原来类名：VerifyCaptcha
	/**
	 * VerifyCaptcha:(图片验证 验证码).
	 * @param
	 * @param captchaikey
	 * @return 
	 * @return :MessageBox 
	 * @Creator:REN GUO QING
	 * @Date:2016年5月12日 下午5:45:30
	 */
	public static Integer verifyCaptcha(String captcha, String captchaikey){
		String key=captchaikey.replace("\"", "").trim().toLowerCase();
		String codea = captcha.trim().toLowerCase();
		if (key.equals(codea)) {
			return 1;
		}
		return 0;
	}
	
	public static String analysisRedisCaptcha(String redisCaptchaValue) {
		return redisCaptchaValue.replace("\"", "").trim().toLowerCase();
	}
//==================================================================================================================
	//原来类名：RandomCaptcha
	private static char[] codeSequence={'A','a','B','b','c','D','d','E','e','F','f','G','g','H','h',
			   'i','J','j','k','L','M','m','N','n','p','Q','q','R','r','s','T','t', 'v', 'W',
			   'u','x','Y','y','z','0','1', '2', '3', '4', '5', '6', '7', '8', '9'};
	/**
	 * GetRandomCode:(获取随机Code).
	 * @param num 获取几位Code
	 * @return 
	 * @return :String 
	 * @Creator:REN GUO QING
	 * @Date:2016年5月12日 下午2:30:44
	 */
	public static String GetRandomCode(Integer num){
		//生成随机类   
	    Random random = new Random();
	    String code="";
	    for (int i = 0; i < num; i++) {
	    	Integer r=random.nextInt(codeSequence.length);
	    	String c = String.valueOf(codeSequence[r]);
	    	code+=c;
	    }
		return code;
	}
	
	public static void main(String[] args) {
		String code= GetRandomCode(4);
		System.out.println(code);
	}
	
}
